import 'package:json_annotation/json_annotation.dart';

part 'news.g.dart';

/// 新闻分页 request
@JsonSerializable()
class NewsPageListRequestEntity {
  String categoryCode;
  String channelCode;
  String tag;
  String keyword;

  NewsPageListRequestEntity({
    required this.categoryCode,
    String channelCode = "",
    String tag = "",
    String keyword = "",
  })  : this.channelCode = channelCode,
        this.tag = tag,
        this.keyword = keyword;

  Map<String, dynamic> toJson() => _$NewsPageListRequestEntityToJson(this);
}

/// 新闻分页 response
@JsonSerializable()
class NewsPageListResponseEntity {
  int counts;
  int pagesize;
  int pages;
  int page;
  List<NewsItem> items;

  NewsPageListResponseEntity({
    required this.counts,
    required this.pagesize,
    required this.pages,
    required this.page,
    required this.items,
  });

  factory NewsPageListResponseEntity.fromJson(Map<String, dynamic> json) =>
      _$NewsPageListResponseEntityFromJson(json);

  Map<String, dynamic> toJson() => _$NewsPageListResponseEntityToJson(this);
}

@JsonSerializable()
class NewsItem {
  String id;
  String title;
  String category;
  String thumbnail;
  String author;
  DateTime addtime;
  String url;

  NewsItem({
    required this.id,
    required this.title,
    required this.category,
    required this.thumbnail,
    required this.author,
    required this.addtime,
    required this.url,
  });

  factory NewsItem.fromJson(Map<String, dynamic> json) =>
      _$NewsItemFromJson(json);

  Map<String, dynamic> toJson() => _$NewsItemToJson(this);
}

/// 新闻推荐 request
@JsonSerializable()
class NewsRecommendRequestEntity {
  String categoryCode;
  String channelCode;
  String tag;
  String keyword;

  NewsRecommendRequestEntity({
    required this.categoryCode,
    String channelCode = "",
    String tag = "",
    String keyword = "",
  })  : this.channelCode = channelCode,
        this.tag = tag,
        this.keyword = keyword;

  Map<String, dynamic> toJson() => _$NewsRecommendRequestEntityToJson(this);
}

/// 新闻推荐 response
@JsonSerializable()
class NewsRecommendResponseEntity {
  String thumbnail;
  String title;
  String category;
  DateTime addtime;
  String author;
  String url;
  String id;

  NewsRecommendResponseEntity({
    required this.thumbnail,
    required this.title,
    required this.category,
    required this.addtime,
    required this.author,
    required this.url,
    required this.id,
  });

  factory NewsRecommendResponseEntity.fromJson(Map<String, dynamic> json) =>
      _$NewsRecommendResponseEntityFromJson(json);

  Map<String, dynamic> toJson() => _$NewsRecommendResponseEntityToJson(this);
}
